package com.example.chevbook_android;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;




import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Matrix;
import android.os.AsyncTask;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class LogementAdapter extends BaseAdapter {
	private List<Logement> ListeL;
	private LayoutInflater inflater;
	private AsyncTask<String, String, Boolean> mthreadcon;
	private ImageLoader imageLoader=ImageLoader.getInstance();
	private Modele vmodele = new Modele();

	public LogementAdapter(Context context,List<Logement> vListeL)
	{
			inflater = LayoutInflater.from(context);
			ListeL = vListeL;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return ListeL.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return ListeL.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	Logement vlogement = new Logement();
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
				
		ViewHolder holder;
	
		if(convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.vuelogement, null);
		    holder.vPrix = ((TextView)convertView.findViewById(R.id.tvEuro));
			holder.vAdr = (TextView)convertView.findViewById(R.id.tvAdr);
			holder.vTitre = (TextView)convertView.findViewById(R.id.tvSurface);
			holder.vDistance = (TextView)convertView.findViewById(R.id.tvDistance);
			holder.vPhoto = (ImageView)convertView.findViewById(R.id.iVPhoto);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		String vPrixConvert = Double.toString(ListeL.get(position).getPrix());
		String vSurfaceConvert = ListeL.get(position).getTitre();
		String vDistanceConvert = Integer.toString(ListeL.get(position).getDistance());
		holder.vAdr.setText(" "+(ListeL.get(position).getAdresse())+ " " + (ListeL.get(position).getCp())+ " " +(ListeL.get(position).getVille()));
		holder.vTitre.setText(" "+vSurfaceConvert);
		holder.vPrix.setText(" "+vPrixConvert);
		holder.vDistance.setText(" "+vDistanceConvert);
		convertView.setBackgroundColor(Color.rgb(255, 255, 255));
			   
		holder.vTitre.setTextColor(Color.rgb(0, 0, 255));
		imageLoader.displayImage(vmodele.recupnumphoto(ListeL.get(position).getId()),holder.vPhoto);
		return convertView;
	}
	
	
	private class ViewHolder {
		TextView vPrix,vAdr,vTitre,vDistance;
		ImageView vPhoto;
	}
	
}
